package com.hl.sfzy.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hl.sfzy.entity.Company;
import com.hl.sfzy.entity.ConsultantCertificates;
import com.hl.sfzy.service.CompanyService;
import com.hl.sfzy.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/company")
public class CompanyController {

    @Autowired
    private CompanyService companyService;

    @GetMapping("/select/{companyId}")
    public R selectCompany(@PathVariable Long companyId) {
        return R.ok(companyService.selectByPrimaryKey(companyId));
    }

   @DeleteMapping("/delete/{companyId}")
    public R deleteCompany(@PathVariable Long companyId) {
        int count = companyService.deleteByPrimaryKey(companyId);
        if (count == 1) {
            return R.ok("删除成功");
        }else {
            return R.ok("删除失败");
        }

   }
    @PostMapping("/add")
    public R insert(@RequestBody Company company) {
        int count = companyService.insert(company);
        if (count == 1) {
            return R.ok("操作成功");
        }else {
            return R.ok("操作失败");
        }
    }
    @PostMapping("/addSelective")
    public R insertSelective(@RequestBody Company company) {
        int count = companyService.insertSelective(company);
        if (count == 1) {
            return R.ok("操作成功");
        }else {
            return R.ok("操作失败");
        }
    }

    @PutMapping("/update")
    public R updateByPrimaryKey(@RequestBody Company company) {
        int count = companyService.updateByPrimaryKeySelective(company);
        if (count == 1) {
            return R.ok("操作成功");
        }else {
            return R.ok("操作失败");
        }
    }

    @PutMapping("/updateSelective")
    public R updateByPrimaryKeySelective(@RequestBody Company company) {
       int count = companyService.updateByPrimaryKeySelective(company);
       if (count == 1) {
           return R.ok("操作成功");
       }else {
           return R.ok("操作失败");
       }
    }
    @GetMapping("/select")
    public R selectAll(@RequestParam(required = false,defaultValue = "1") int pageNum,
                       @RequestParam(required = false,defaultValue = "5") int pageSize){
        PageHelper.startPage(pageNum,pageSize);
        PageInfo<Company> info = new PageInfo<>(companyService.selectAll());
        return R.ok(info);
    }

}
